package arithmetic.string;

/**
 * 字符串操作
 */
public class ReverseString {

    // 递归翻转
    public static String reverse(String str) {
        if (str.length() <= 1) {
            return str;
        }
        return reverse(str.substring(1)) + str.charAt(0);
    }

    // 方法一
    public static String reserveString(String s) {
        int length = s.length();
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < length; i++) {
            result.append(s.charAt(i));
        }
        return result.toString();
    }

    // 方法二
    public static String revereString2(String s) {
        char[] a = s.toCharArray();
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < a.length; i++) {
            result.append(a[i]);
        }
        return result.toString();
    }

    // 方法三
    public static String revereString3(String s) {
        StringBuilder stringBuilder = new StringBuilder(s);
        String result = stringBuilder.reverse().toString();
        return result;
    }

    public static void main(String[] args) {
        String a = "fsdfsadee";
        System.out.println(reserveString(a));
    }
}
